<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let s = 7
        let nums = [2,3,1,2,4,3]
        function solution(nums, s) {
            let res = Infinity
            let subLength = 0
            let i = 0
            let sum = 0
            for(let j=0; j<nums.length; j++) {
                sum += nums[j]
                while(sum >= s) {
                    subLength = (j - i) + 1
                    res = res < subLength ? res : subLength
                    sum -= nums[i++]
                }
            }

            return res === Infinity ? 0 : res
        }

        const res = solution(nums, s)
        console.log(res)

    </script>
</body>
</html>